//
//  BKMain_EvaluateAlertView.m
//  bestkeep
//
//  Created by utouu on 17/1/11.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKMain_EvaluateAlertView.h"

#define kImageWidth ScreenWidth/3.0f*2.0f
#define kImageHeight kImageWidth*540.0f/433.0f

@interface BKMain_EvaluateAlertView()

@property (nonatomic, strong) UIImageView *mainImageView;

@end

@implementation BKMain_EvaluateAlertView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
        self.mainImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BKMain_EvaluateAlertViewImage"]];
        self.mainImageView.userInteractionEnabled = YES;
        self.mainImageView.alpha = 0;
        [self addSubview:self.mainImageView];
        self.mainImageView.bounds = CGRectMake(0, 0, kImageWidth, kImageHeight);
        self.mainImageView.center = CGPointMake(ScreenWidth/2.0f, ScreenHeight/2.0f);
        
        UIButton *goodEvaluate = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mainImageView addSubview:goodEvaluate];
        [goodEvaluate addTarget:self action:@selector(goodEvaluateAction) forControlEvents:UIControlEventTouchUpInside];
        [goodEvaluate setFrame:CGRectMake(0, 330.0f/540.0f*kImageHeight, kImageWidth, 75.0f/540.0f*kImageHeight)];
        
        UIButton *badEvaluate = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mainImageView addSubview:badEvaluate];
        [badEvaluate addTarget:self action:@selector(badEvaluateAction) forControlEvents:UIControlEventTouchUpInside];
        [badEvaluate setFrame:CGRectMake(0, 405.0f/540.0f*kImageHeight, kImageWidth, 65.0f/540.0f*kImageHeight)];
        
        UIButton *goShopping = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mainImageView addSubview:goShopping];
        [goShopping addTarget:self action:@selector(goShoppingAction) forControlEvents:UIControlEventTouchUpInside];
        [goShopping setFrame:CGRectMake(0, 470.0f/540.0f*kImageHeight, kImageWidth, 70.0f/540.0f*kImageHeight)];
    }
    return self;
}

- (void)goodEvaluateAction {
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%d&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8", 1035553463]]];
    [self hiddenAllView];
}
- (void)badEvaluateAction {
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%d&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8", 1035553463]]];
    [self hiddenAllView];
}
- (void)goShoppingAction {
    
    [self hiddenAllView];
}


#pragma mark - show and dismiss
-(UIView*)topView{
    return  [[[UIApplication sharedApplication] delegate] window];
}
- (void)show {
    [[self topView] addSubview:self];
    [UIView animateWithDuration:0.5 animations:^{
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        self.mainImageView.alpha = 1;
    } completion:^(BOOL finished) {
    }];
}

- (void)hiddenAllView {
    
    [UIView animateWithDuration:0.3f animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
